package A002lock8;

import java.util.concurrent.TimeUnit;


// 有两部手机，请问先打印邮件还是短信？
// -----sendSMS
// -----sendEmail

class Phone04 {
    public synchronized void sendEmail() throws Exception {
        TimeUnit.SECONDS.sleep(4);
        System.out.println("-----sendEmail");
    }

    public synchronized void sendSMS() throws Exception {
        System.out.println("-----sendSMS");
    }
}


public class A002_线程八锁_4 {
    public static void main(String[] args) throws InterruptedException {

        Phone04 phone04_1 = new Phone04();
        Phone04 phone04_2 = new Phone04();

        new Thread(() -> {
            try {
                phone04_1.sendEmail();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "A").start();

        Thread.sleep(100);

        new Thread(() -> {
            try {
                phone04_2.sendSMS();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "B").start();
    }
}
